package exercise;

import org.junit.jupiter.api.Test;

import java.io.*;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-28
 * Time:22:37
 */
@SuppressWarnings("all")
public class Exercise3 {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        properties.load(new FileReader("src/exercise/dog.properties"));
        Dog dog = new Dog();
        dog.setName(properties.getProperty("name"));
        dog.setAge(Integer.parseInt(properties.getProperty("age")));
        dog.setColor(properties.getProperty("color"));
        System.out.println(dog.toString());
        String filePath = "f:/Test/dog.txt";
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filePath));
        oos.writeObject(dog);
        oos.close();
    }
    @Test
    public void func() throws IOException, ClassNotFoundException {
        String filePath = "f:/Test/dog.txt";
        ObjectInputStream ois = null;
        ois = new ObjectInputStream(new FileInputStream(filePath));
        Dog dog = null;
        dog = (Dog) ois.readObject();
        System.out.println(dog.toString());
    }
}
class Dog implements Serializable {
    String name;
    int age;
    String color;

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", color='" + color + '\'' +
                '}';
    }
}
